﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using CustomTypes.Interfaces;
using Mono.Cecil;

namespace devtm.AutoMapper.TemplateAdd.Models
{
    
    [CLSCompliant(false)]
    public class TypeBox : TreeViewItem
    {


        internal static byte[] imgClass162 = devtm.AutoMapper.Properties.Resources.Class162.GetBytes();

        public TypeDefinition Type {get; private set;}
        private AssemblyBox _root;

      
        #region Ctor


        public TypeBox()
        {
            Items.SortDescriptions.Add(new System.ComponentModel.SortDescription("MyName", System.ComponentModel.ListSortDirection.Ascending));
        }


        public TypeBox(AssemblyBox root, TypeDefinition type)
            : this()
        {

            this.Type = type;
            this._root = root;

            ContextTitle = new ContainerHeader() { Label = type.Name, ImageSource = imgClass162 };
            Header = new HeaderCtrl() { Context = ContextTitle };

        }        



        #endregion


        internal ContainerHeader ContextTitle { get; set; }
     
        protected override void OnSelected(System.Windows.RoutedEventArgs e)
        {

            base.OnSelected(e);

            _root.Select(this);
            
        }

        protected override void OnKeyDown(System.Windows.Input.KeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (e.Key == System.Windows.Input.Key.Enter | e.Key == System.Windows.Input.Key.Return)
            {

                _root.Select(this);

                var frm = this._root.Form;
                frm.DialogResult = System.Windows.Forms.DialogResult.OK;
                frm.Close();

            }

        }
    
    }
}
